<?php

### Error handling

function PHPGWTErrorHandler($errno, $errstr, $errfile, $errline){
 die("Error #".$errno." in ".$errfile." at line ".$errline.": ".$errstr);
}

set_error_handler("PHPGWTErrorHandler");

### Processing request

$data = json_decode(stripslashes($_POST['data']));

if(!$data){
  die('Error parsing request:'.$_POST['data']);
}

$service = $data->{'service'};
$function = $data->{'function'};
$parameters = (array) $data->parameters;

$services = array();
$files = array();
$ret = NULL;

### Service definitions

$files['PrimitiveTestService'] = 'PrimitiveTestService.php';
$services['PrimitiveTestService'] = array();
$services["PrimitiveTestService"][] = "getByte";

### Request validation and execution

if(in_array($function, $services[$service])){
  require $files[$service];
  $ret = call_user_func_array($function, $parameters);
}

print json_encode($ret);

?>
